#include "VSSceneRender.h"
#include "VSGraphicInclude.h"
#include "VSNormalDepthPass.h"
#include "VSPrezPass.h"
using namespace VSEngine2;
VSSceneRenderInterface::VSSceneRenderInterface()
{
	m_uiClearFlag = VSRenderer::CF_USE_MAX;
	m_ClearColorRGBA = VSColorRGBA(0.0f,0.0f,0.0f,1.0f);
	m_fClearDepth = 1.0f;
	m_uiClearStencil = 0;
	m_uiRenderStateInheritFlag = 0;
	m_bUseViewPortClear = false;
	m_uiRTWidth = 0;
	m_uiRTHeight = 0;
}
VSSceneRenderInterface::~VSSceneRenderInterface()
{
	m_pTargetArray.Clear();
}
VSRenderTarget * VSSceneRenderInterface::GetRenderTarget(unsigned int uiIndex)
{
	if (uiIndex >= m_pTargetArray.GetNum())
	{
		return NULL;
	}
	return m_pTargetArray[uiIndex];
}
void VSSceneRenderInterface::SetUseState(VSRenderState & RenderState,unsigned int uiRenderStateInheritFlag)
{
	m_UseState.GetAll(&RenderState);
	m_uiRenderStateInheritFlag = uiRenderStateInheritFlag;
}
void VSSceneRenderInterface::ClearUseState()
{
	m_uiRenderStateInheritFlag = 0;	
}
bool VSSceneRenderInterface::AddRenderTarget(VSRenderTarget * pTarget)
{
	for (unsigned int i = 0 ; i < m_pTargetArray.GetNum() ; i++)
	{
		if (pTarget == m_pTargetArray[i])
		{
			return false;
		}
	}
	if (!pTarget)
	{
		return false;
	}
	if (!pTarget->GetWidth() || !pTarget->GetHeight())
	{
		return false;
	}
	if (m_uiRTHeight && m_uiRTWidth)
	{
		if (m_uiRTWidth != pTarget->GetWidth() || m_uiRTHeight != pTarget->GetHeight())
		{
			return false;
		}
	}
	else
	{	
		m_uiRTHeight = pTarget->GetWidth();
		m_uiRTHeight = pTarget->GetHeight();
	}

	m_pTargetArray.AddElement(pTarget);

	return true;
}
VSSceneRender::VSSceneRender()
{
	for (unsigned int i = 0 ; i < VSCuller::RG_MAX ; i++)
	{
		m_pDepthStencil[i] = NULL;
	}
}
VSSceneRender::~VSSceneRender()
{
	
	for (unsigned int i = 0 ; i < VSCuller::RG_MAX ; i++)
	{
		m_pDepthStencil[i] = NULL;
	}
}

bool VSSceneRender::SetDepthStencil(VSDepthStencil * pDepthStencil,unsigned int uiRenderGroup)
{
	if (uiRenderGroup >= VSCuller::RG_MAX)
	{
		return false;
	}
	if (!pDepthStencil->GetWidth() || !pDepthStencil->GetHeight())
	{
		return false;
	}
	if (!pDepthStencil)
	{
		if (m_uiRTHeight && m_uiRTWidth)
		{
			if (m_uiRTWidth != pDepthStencil->GetWidth() || m_uiRTHeight != pDepthStencil->GetHeight())
			{
				return false;
			}
		}
		else
		{	
			m_uiRTWidth = pDepthStencil->GetWidth();
			m_uiRTHeight = pDepthStencil->GetHeight();
		}
	}
	
	m_pDepthStencil[uiRenderGroup] = pDepthStencil;
	return true;
}
void VSSceneRender::ClearRTAndDepth()
{
	m_pTargetArray.Clear();
	m_uiRTWidth = 0;
	m_uiRTHeight = 0;
	for (unsigned int i = 0 ; i < VSCuller::RG_MAX ; i++)
	{
		m_pDepthStencil[i] = NULL;
	}
}
bool VSSceneRender::Draw(VSCuller & Culler,double dAppTime)
{

	for (unsigned int i = 0 ; i < m_pTargetArray.GetNum() ; i++)
	{
		if (i >= VSRenderer::ms_pRenderer->GetMaxRTNum())
		{
			break;
		}
		VSRenderer::ms_pRenderer->SetRenderTarget(m_pTargetArray[i],i);

	}


	if (m_uiClearFlag <= VSRenderer::CF_USE_MAX)
	{

		VSColorRGBA ClearColorRGBA = VSRenderer::ms_pRenderer->GetClearColor();
		VSREAL fClearDepth = VSRenderer::ms_pRenderer->GetClearDepth();
		unsigned int uiClearStencil = VSRenderer::ms_pRenderer->GetClearStencil();

		VSRenderState SaveRenderState = VSRenderer::ms_pRenderer->GetUseState();
		unsigned int uiSaveRenderStateInheritFlag = VSRenderer::ms_pRenderer->GetRenderStateInheritFlag();

		VSRenderer::ms_pRenderer->SetClearColor(m_ClearColorRGBA);
		VSRenderer::ms_pRenderer->SetClearDepth(m_fClearDepth);
		VSRenderer::ms_pRenderer->SetClearStencil(m_uiClearStencil);

		if (m_uiRenderStateInheritFlag)
		{			
			VSRenderer::ms_pRenderer->SetUseState(m_UseState,m_uiRenderStateInheritFlag);		
		}
		if (Culler.GetCamera()->GetViewPointNum())
		{
			if (!m_bUseViewPortClear)
			{
				VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_COLOR);
			}
			for (unsigned int i = 0 ; i< Culler.GetCamera()->GetViewPointNum() ;i++)
			{
				float fAspect = Culler.GetCamera()->GetAspect();
				VSRenderer::ms_pRenderer->SetViewPort(Culler.GetCamera(),i);
				unsigned int MinX,MinY,MaxX,MaxY;
				if (m_bUseViewPortClear)
				{		
					VSRenderer::ms_pRenderer->GetCurRTViewPortRect(Culler.GetCamera(),i,MinX,MinY,MaxX,MaxY);	
					VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_COLOR,MinX,MinY,(MaxX - MinX),(MaxY - MinY));
				}
				for (unsigned int uiRenderGroup = 0 ; uiRenderGroup < VSCuller::RG_MAX ;uiRenderGroup++)
				{	
					if (!Culler.GetRenderGroupVisibleNum(uiRenderGroup))
					{
						continue;
					}
					if (m_pDepthStencil[uiRenderGroup])
					{
						VSRenderer::ms_pRenderer->SetDepthStencilBuffer(m_pDepthStencil[uiRenderGroup]);
					
						if (!m_bUseViewPortClear)
						{
							VSRenderer::ms_pRenderer->ClearBuffers(VSRenderer::CF_DEPTH & m_uiClearFlag);
						}
						else
						{
							VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_DEPTH,MinX,MinY,(MaxX - MinX),(MaxY - MinY));
						}
						OnDraw(Culler,uiRenderGroup);
						VSRenderer::ms_pRenderer->EndDepthStencilBuffer(m_pDepthStencil[uiRenderGroup]);
					}
					else
					{
						if (!m_bUseViewPortClear)
						{
							VSRenderer::ms_pRenderer->ClearBuffers(VSRenderer::CF_DEPTH & m_uiClearFlag);
						}
						else
						{
							VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_DEPTH,MinX,MinY,(MaxX - MinX),(MaxY - MinY));
						}
						OnDraw(Culler,uiRenderGroup);
					}
				}
				Culler.GetCamera()->SetAspect(fAspect);
			}

		}
		else
		{
			VSRenderer::ms_pRenderer->SetViewPort(NULL);
			VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag);
			for (unsigned int uiRenderGroup = 0 ; uiRenderGroup < VSCuller::RG_MAX ;uiRenderGroup++)
			{
				if (!Culler.GetRenderGroupVisibleNum(uiRenderGroup))
				{
					continue;
				}
				if (m_pDepthStencil[uiRenderGroup])
				{
					VSRenderer::ms_pRenderer->SetDepthStencilBuffer(m_pDepthStencil[uiRenderGroup]);
					VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_DEPTH);									
					OnDraw(Culler,uiRenderGroup);
					VSRenderer::ms_pRenderer->EndDepthStencilBuffer(m_pDepthStencil[uiRenderGroup]);
				}
				else
				{
					VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag & VSRenderer::CF_DEPTH);									
					OnDraw(Culler,uiRenderGroup);
				}
			}
			
		}
		
		VSRenderer::ms_pRenderer->SetClearColor(ClearColorRGBA);
		VSRenderer::ms_pRenderer->SetClearDepth(fClearDepth);
		VSRenderer::ms_pRenderer->SetClearStencil(uiClearStencil);
		if (m_uiRenderStateInheritFlag)
		{
			VSRenderer::ms_pRenderer->SetUseState(SaveRenderState,uiSaveRenderStateInheritFlag);
		}
	}



	for (unsigned int i = 0 ; i < m_pTargetArray.GetNum() ; i++)
	{
		if (i >= VSRenderer::ms_pRenderer->GetMaxRTNum())
		{
			break;
		}
		VSRenderer::ms_pRenderer->EndRenderTarget(m_pTargetArray[i],i);

	}

	return true;
}
VSDebugDrawSceneRender::VSDebugDrawSceneRender()
{
	for (unsigned int i =0 ; i < VSCuller::RG_MAX ;i++)
	{
		m_pDebugDraw[i] = VS_NEW VSDebugDraw();

	}
}
VSDebugDrawSceneRender::~VSDebugDrawSceneRender()
{
	for (unsigned int i =0 ; i < VSCuller::RG_MAX ;i++)
	{
		m_pDebugDraw[i] = NULL;
	}
}
bool VSDebugDrawSceneRender::OnDraw(VSCuller & Culler,unsigned int uiRenderGroup)
{
	if (m_pDebugDraw[uiRenderGroup])
	{
		m_pDebugDraw[uiRenderGroup]->DrawDebugInfo(Culler.GetCamera());
	}
	return true;
}
VSMaterialSceneRender::VSMaterialSceneRender()
{

}
VSMaterialSceneRender::~VSMaterialSceneRender()
{

}
bool VSMaterialSceneRender::OnDraw(VSCuller & Culler,unsigned int uiRenderGroup)
{

	
	//Render
	for (unsigned int t = 0 ; t < VSCuller::VST_MAX ; t++)
	{
		for(unsigned int j = 0; j < Culler.GetVisibleNum(t,uiRenderGroup) ; j++)
		{
			VSRenderContext& VisibleContext = Culler.GetVisibleSpatial(j,t,uiRenderGroup);
			if (!VisibleContext.m_pSpatial || !VisibleContext.m_pMaterialInstance)
			{
				continue ;
			}
			if (VisibleContext.m_pSpatial->GetST() != VSSpatial::ST_GEOMETRY)
			{
				continue;
			}
			VSGeometry * pGeometry = (VSGeometry *)VisibleContext.m_pSpatial;




			VSMaterialInstance * pMaterialInstance = VisibleContext.m_pMaterialInstance;

			VSMaterialPass * pMaterialPass = pMaterialInstance->GetMaterial()->GetMaterialPass();

			for(unsigned int l = 0 ; l < Culler.GetLightNum() ; l++)
			{
				VSLight * pLight = Culler.GetLight(l);
				if (pLight->IsRelative(pGeometry))
				{
					pMaterialPass->AddLight(pLight);
				}
			}
			pMaterialPass->SetPassId(VisibleContext.m_uiPassId);
			pMaterialPass->SetSpatial(pGeometry);
			pMaterialPass->SetMaterialInstance(pMaterialInstance);	
			pMaterialPass->SetCamera(Culler.GetCamera());
			pMaterialPass->Draw(VSRenderer::ms_pRenderer);





		}
	}
	
	return true;
}
VSNormalDepthSceneRender::VSNormalDepthSceneRender()
{

}
VSNormalDepthSceneRender::~VSNormalDepthSceneRender()
{

}
bool VSNormalDepthSceneRender::OnDraw(VSCuller & Culler,unsigned int uiRenderGroup)
{
	

	for (unsigned int t = 0 ; t < VSCuller::VST_MAX ; t++)
	{
		for(unsigned int j = 0; j < Culler.GetVisibleNum(t,uiRenderGroup) ; j++)
		{
			VSRenderContext& VisibleContext = Culler.GetVisibleSpatial(j,t,uiRenderGroup);
			if (!VisibleContext.m_pSpatial || !VisibleContext.m_pMaterialInstance)
			{
				continue ;
			}
			VSMaterial * pMaterial = VisibleContext.m_pMaterialInstance->GetMaterial();
			if (!pMaterial)
			{
				continue;
			}
			const VSBlendDesc & BlendDest = pMaterial->GetRenderState(VisibleContext.m_uiPassId).GetBlendState()->GetBlendDesc();
			if (BlendDest.IsBlendUsed())
			{
				continue;
			}
			const VSDepthStencilDesc & DepthStencilDest = pMaterial->GetRenderState(VisibleContext.m_uiPassId).GetDepthStencilState()->GetDepthStencilDesc();

			if (VisibleContext.m_pSpatial->GetST() != VSSpatial::ST_GEOMETRY)
			{
				continue;
			}
			VSGeometry * pGeometry = (VSGeometry *)VisibleContext.m_pSpatial;
			unsigned int uiNormalLevel = pGeometry->GetMeshDate()->GetVertexBuffer()->GetNormalLevel();
			if (!DepthStencilDest.m_bDepthWritable && !uiNormalLevel)
			{
				continue;
			}
			

			VSMaterialInstance * pMaterialInstance = VisibleContext.m_pMaterialInstance;			
			VSNormalDepthPass * pNormalDepthPass = pMaterialInstance->GetMaterial()->GetNormalDepthPass();
			pNormalDepthPass->SetPassId(VisibleContext.m_uiPassId);
			pNormalDepthPass->SetSpatial(pGeometry);
			pNormalDepthPass->SetMaterialInstance(pMaterialInstance);	
			pNormalDepthPass->SetCamera(Culler.GetCamera());
			pNormalDepthPass->Draw(VSRenderer::ms_pRenderer);
		}
	}
	return true;
}

VSPrezSceneRender::VSPrezSceneRender()
{

}
VSPrezSceneRender::~VSPrezSceneRender()
{

}
bool VSPrezSceneRender::OnDraw(VSCuller & Culler,unsigned int uiRenderGroup)
{
	//PreZ
	for (unsigned int t = 0 ; t < VSCuller::VST_MAX ; t++)
	{
		for(unsigned int j = 0; j < Culler.GetVisibleNum(t,uiRenderGroup) ; j++)
		{
			VSRenderContext& VisibleContext = Culler.GetVisibleSpatial(j,t,uiRenderGroup);
			if (!VisibleContext.m_pSpatial || !VisibleContext.m_pMaterialInstance)
			{
				continue ;
			}
			if (VisibleContext.m_pSpatial->GetST() != VSSpatial::ST_GEOMETRY)
			{
				continue;
			}
			VSGeometry * pGeometry = (VSGeometry *)VisibleContext.m_pSpatial;

			VSMaterialInstance * pMaterialInstance = VisibleContext.m_pMaterialInstance;			

			VSPrezPass * pPrezPass = VSPrezPass::GetDefault();
			pPrezPass->SetSpatial(pGeometry);
			pPrezPass->SetMaterialInstance(pMaterialInstance);	
			pPrezPass->SetCamera(Culler.GetCamera());
			pPrezPass->Draw(VSRenderer::ms_pRenderer);
		}
	}
	return true;
}
VSPostEffectSceneRender::VSPostEffectSceneRender()
{
	m_pTexAllState = VS_NEW VSTexAllState();
	m_uiClearFlag = VSRenderer::CF_COLOR;
	m_pDepthStencil = NULL;
}
VSPostEffectSceneRender::~VSPostEffectSceneRender()
{
	m_pDepthStencil = NULL;
	m_pTexAllState = NULL;
}
bool VSPostEffectSceneRender::SetDepthStencil(VSDepthStencil * pDepthStencil)
{
	if (!pDepthStencil)
	{
		return false;
	}
	if (!pDepthStencil->GetWidth() || !pDepthStencil->GetHeight())
	{
		return false;
	}
	if (m_uiRTHeight && m_uiRTWidth)
	{
		if (m_uiRTWidth != pDepthStencil->GetWidth() || m_uiRTHeight != pDepthStencil->GetHeight())
		{
			return false;
		}
	}
	else
	{	
		m_uiRTWidth = pDepthStencil->GetWidth();
		m_uiRTHeight = pDepthStencil->GetHeight();
	}
	m_pDepthStencil = pDepthStencil;
	return true;
}
void VSPostEffectSceneRender::CreateRT(unsigned int uiWidth,unsigned int uiHeight)
{
	m_pTargetArray.Clear();
	m_pDepthStencil = NULL;
	VS2DTexture * pTexture = VS_NEW VS2DTexture(uiWidth,uiHeight,VSRenderer::SFT_X8R8G8B8);
	VSRenderTarget * pRenderTarget = VSResourceManager::CreateRenderTarget(pTexture,VSRenderer::MS_NONE);
	AddRenderTarget(pRenderTarget);
}
bool VSPostEffectSceneRender::IsReCreate(unsigned int uiWidth,unsigned int uiHeight)
{

	if (m_uiRTWidth == uiWidth && m_uiRTHeight == uiHeight)
	{
		return false;
	}


	return true;
}
void VSPostEffectSceneRender::SetSourceTarget(VSTexture * pTexture)
{
	m_pTexAllState->m_pTex = pTexture;
}
bool VSPostEffectSceneRender::Draw(VSCuller & Culler,double dAppTime)
{

	for (unsigned int i = 0 ; i < m_pTargetArray.GetNum() ; i++)
	{
		if (i >= VSRenderer::ms_pRenderer->GetMaxRTNum())
		{
			break;
		}
		VSRenderer::ms_pRenderer->SetRenderTarget(m_pTargetArray[i],i);

	}

	if (m_pDepthStencil)
	{
		if(!VSRenderer::ms_pRenderer->SetDepthStencilBuffer(m_pDepthStencil))
		{
			VSMAC_ASSERT(0);
			return false;
		}
	}

	if (m_uiClearFlag > 0 && m_uiClearFlag <= VSRenderer::CF_USE_MAX)
	{

		VSColorRGBA ClearColorRGBA = VSRenderer::ms_pRenderer->GetClearColor();
		VSREAL fClearDepth = VSRenderer::ms_pRenderer->GetClearDepth();
		unsigned int uiClearStencil = VSRenderer::ms_pRenderer->GetClearStencil();

		VSRenderState SaveRenderState = VSRenderer::ms_pRenderer->GetUseState();
		unsigned int uiSaveRenderStateInheritFlag = VSRenderer::ms_pRenderer->GetRenderStateInheritFlag();

		VSRenderer::ms_pRenderer->SetClearColor(m_ClearColorRGBA);
		VSRenderer::ms_pRenderer->SetClearDepth(m_fClearDepth);
		VSRenderer::ms_pRenderer->SetClearStencil(m_uiClearStencil);

		if (m_uiRenderStateInheritFlag)
		{			
			VSRenderer::ms_pRenderer->SetUseState(m_UseState,m_uiRenderStateInheritFlag);		
		}
		
		VSRenderer::ms_pRenderer->SetViewPort(NULL);
		VSRenderer::ms_pRenderer->ClearBuffers(m_uiClearFlag);
		OnDraw(Culler);
		


		VSRenderer::ms_pRenderer->SetClearColor(ClearColorRGBA);
		VSRenderer::ms_pRenderer->SetClearDepth(fClearDepth);
		VSRenderer::ms_pRenderer->SetClearStencil(uiClearStencil);
		if (m_uiRenderStateInheritFlag)
		{
			VSRenderer::ms_pRenderer->SetUseState(SaveRenderState,uiSaveRenderStateInheritFlag);
		}
	}



	for (unsigned int i = 0 ; i < m_pTargetArray.GetNum() ; i++)
	{
		if (i >= VSRenderer::ms_pRenderer->GetMaxRTNum())
		{
			break;
		}
		VSRenderer::ms_pRenderer->EndRenderTarget(m_pTargetArray[i],i);

	}

	if (m_pDepthStencil)
	{
		if(!VSRenderer::ms_pRenderer->EndDepthStencilBuffer(m_pDepthStencil))
		{
			VSMAC_ASSERT(0);
			return false;
		}
	}
	return true;
}
VSPEBlurSceneRender::VSPEBlurSceneRender()
{
	
};
VSPEBlurSceneRender::~VSPEBlurSceneRender()
{

};
VSPEGraySceneRender::VSPEGraySceneRender()
{
	m_pGrayMaterial = VSCustomMaterial::GetPostGray();
};
VSPEGraySceneRender::~VSPEGraySceneRender()
{
	m_pGrayMaterial = NULL;
};
void VSPEGraySceneRender::SetSourceTarget(VSTexture * pTexture)
{
	VSPostEffectSceneRender::SetSourceTarget(pTexture);
	m_pGrayMaterial->SetPShaderTexture(VSUsedName::ms_cPostInputTexture,m_pTexAllState);
}
bool VSPEGraySceneRender::OnDraw(VSCuller & Culler)
{
	
	if (!m_pTargetArray.GetNum())
	{
		return false;
	}
	if (!m_pTargetArray[0])
	{
		return false;
	}
	unsigned int uiWidth = m_pTargetArray[0]->GetWidth();
	unsigned int uiHeight = m_pTargetArray[0]->GetHeight();
	if (!uiWidth || !uiHeight)
	{
		return false;
	}
// 	VSRenderer::SCREEN_QUAD_TYPE FullScreen[4] = 
// 	{
// 		{VSVector3W(-1.0f,  1.0f, 0.0f,1.0f),VSVector2(0.5f / uiWidth, 0.5f / uiHeight)},
// 		{VSVector3W( 1.0f,  1.0f, 0.0f,1.0f),VSVector2(1.0f, 0.5f / uiHeight)},
// 		{VSVector3W( 1.0f, -1.0f, 0.0f,1.0f),VSVector2(1.0f, 1.0f)},
// 		{VSVector3W(-1.0f, -1.0f, 0.0f,1.0f),VSVector2(0.5f / uiWidth, 1.0f)}	
// 
// 	};
	VSREAL Inv_Width = 1.0f / uiWidth;
	VSREAL Inv_Height = 1.0f / uiHeight;
	m_pGrayMaterial->SetVShaderValue(VSUsedName::ms_cPostInv_Width,&Inv_Width,sizeof(VSREAL));
	m_pGrayMaterial->SetVShaderValue(VSUsedName::ms_cPostInv_Height,&Inv_Height,sizeof(VSREAL));
	if(!m_pGrayMaterial->UseMaterial())
		return false;
	VSRenderer::ms_pRenderer->DrawScreen(NULL);
	return true;
}



VSPEScreenQuadSceneRender::VSPEScreenQuadSceneRender()
{
	m_pScreenQuadMaterial = VSCustomMaterial::GetPostScreenQuad();

};
VSPEScreenQuadSceneRender::~VSPEScreenQuadSceneRender()
{
	m_pScreenQuadMaterial = NULL;
};
void VSPEScreenQuadSceneRender::SetSourceTarget(VSTexture * pTexture)
{
	VSPostEffectSceneRender::SetSourceTarget(pTexture);
	m_pScreenQuadMaterial->SetPShaderTexture(VSUsedName::ms_cPostInputTexture,m_pTexAllState);
}
void VSPEScreenQuadSceneRender::CreateRT(unsigned int uiWidth,unsigned int uiHeight)
{
	m_uiRTHeight = uiHeight;
	m_uiRTWidth = uiWidth;
}
bool VSPEScreenQuadSceneRender::IsReCreate(unsigned int uiWidth,unsigned int uiHeight)
{

	if (m_uiRTWidth == uiWidth && m_uiRTHeight == uiHeight)
	{
		return false;
	}
	return true;
}
bool VSPEScreenQuadSceneRender::OnDraw(VSCuller & Culler)
{

	unsigned int uiWidth = m_uiRTWidth;
	unsigned int uiHeight = m_uiRTHeight;
	if (!uiWidth || !uiHeight)
	{
		return false;
	}
	VSREAL Inv_Width = 1.0f / uiWidth;
	VSREAL Inv_Height = 1.0f / uiHeight;
	m_pScreenQuadMaterial->SetVShaderValue(VSUsedName::ms_cPostInv_Width,&Inv_Width,sizeof(VSREAL));
	m_pScreenQuadMaterial->SetVShaderValue(VSUsedName::ms_cPostInv_Height,&Inv_Height,sizeof(VSREAL));
// 	VSRenderer::SCREEN_QUAD_TYPE FullScreen[4] = 
// 	{
// 		{VSVector3W(-1.0f,  1.0f, 0.0f,1.0f),VSVector2(0.5f / uiWidth, 0.5f / uiHeight)},
// 		{VSVector3W( 1.0f,  1.0f, 0.0f,1.0f),VSVector2(1.0f, 0.5f / uiHeight)},
// 		{VSVector3W( 1.0f, -1.0f, 0.0f,1.0f),VSVector2(1.0f, 1.0f)},
// 		{VSVector3W(-1.0f, -1.0f, 0.0f,1.0f),VSVector2(0.5f / uiWidth, 1.0f)}	
// 
// 	};
	if(!m_pScreenQuadMaterial->UseMaterial())
		return false;
	VSRenderer::ms_pRenderer->DrawScreen(NULL);
	return true;
}
VSShadowMapSceneRender::VSShadowMapSceneRender()
:VSSceneRenderInterface()
{


}
VSShadowMapSceneRender::~VSShadowMapSceneRender()
{

}

bool VSShadowMapSceneRender::OnDraw(VSCuller & Culler)
{
	

	return true;
}